package com.rental.web.service.impl;

import com.rental.common.exception.ProjectException;
import com.rental.common.result.AjaxResult;
import com.rental.client.CosFeignClient;
import com.rental.common.result.ResultCodeEnum;
import com.rental.common.util.AjaxResultHandler;
import com.rental.houses.client.RentalHourseFeign;
import com.rental.model.entity.house.RentalHourse;
import com.rental.model.entity.user.UserInfo;
import com.rental.model.form.hourse.InsertRentalHourseForm;
import com.rental.model.form.hourse.RentalHourseForm;
import com.rental.model.vo.PageVo;
import com.rental.quickenPoint.client.UserAccountClient;
import com.rental.user.client.UserInfoFeignClient;
import com.rental.web.service.RentalHourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RentalHourseServiceImpl implements RentalHourseService {

    @Autowired
    private RentalHourseFeign rentalHourseFeign;
    @Autowired
    private CosFeignClient cosFeignClient;
    @Autowired
    private UserInfoFeignClient userInfoFeignClient;
    @Autowired
    private UserAccountClient userAccountClient;

    /***
     * 获取房屋列表
     * @return
     */
    @Override
    public List<RentalHourse> getRentalHourseList() {
        return rentalHourseFeign.getRentalHourseList().getData();
    }

    /**
     * 根据查询条件获取房屋列表
     * @param rentalHourseForm
     * @return
     */
    @Override
    public AjaxResult<PageVo<RentalHourse>> getRentalHourseListBySearch(RentalHourseForm rentalHourseForm) {
        return rentalHourseFeign.getRentalHourseListBySearch(rentalHourseForm);
    }

    /**
     * 房屋详情
     * @param id,uid  id:房屋id uid:用户id(非房东id)
     * @return
     */
    @Override
    public AjaxResult<RentalHourse> getRentalHourseDetail(Long id, Long uid) {
        return rentalHourseFeign.getRentalHourseDetail(id,uid);
    }

    /**
     * 新增出租屋
     * @param insertRentalHourseForm
     * @return
     */
    @Override
    public AjaxResult<Boolean> insertRentalHourse(InsertRentalHourseForm insertRentalHourseForm) {
        // 增加加速值
        if (!AjaxResultHandler.handle(userAccountClient.sendAccelerateValueByAddInfo(insertRentalHourseForm.getUid())))
            throw new ProjectException(ResultCodeEnum.QUICKEN_ADD_ERROR);
        return rentalHourseFeign.insertRentalHourse(insertRentalHourseForm);
    }

    /**
     * 获取房东微信
     * @param id 房源id
     * @param uid 房东id
     * @return
     */
    @Override
    public AjaxResult<String> getLandlordWechat(Long id, Long uid) {
        return rentalHourseFeign.getLandlordWechat(id,uid);
    }

    /**
     * 获取房东电话
     * @param id 房源id
     * @param uid 房东id
     * @return
     */
    @Override
    public AjaxResult<String> getLandlordPhone(Long id, Long uid) {
        return rentalHourseFeign.getLandlordPhone(id,uid);
    }

    @Override
    public AjaxResult<Boolean> changeStatus(Long id, Long uid) {
        return rentalHourseFeign.changeStatus(id,uid);
    }

    @Override
    public AjaxResult<Boolean> collectHouse(Long id, Long uid) {
        return rentalHourseFeign.collectHouse(id,uid);
    }

    @Override
    public AjaxResult<Boolean> cancelCollectHouse(Long id, Long uid) {
        return rentalHourseFeign.cancelCollectHouse(id,uid);
    }

    @Override
    public AjaxResult<Long> getValidRentalHourseCount() {
        return rentalHourseFeign.getValidRentalHourseCount();
    }

    @Override
    public AjaxResult<Boolean> accusation(Long id) {
        return rentalHourseFeign.accusation(id);
    }

    @Override
    public AjaxResult<UserInfo> getPublishUserInfo(Long id) {
        return userInfoFeignClient.getUserInfoById(id);
    }
}
